<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<title></title>
	<link rel="stylesheet" href="/public/layui/css/layui.css">
	<link rel="stylesheet" href="/public/css/common.css">
	<script src="/public/js/jquery.min.js"></script>
</head>
<body>
	<div class="page-content layui-anim layui-anim-upbit">
    <div class="layui-form">
      <!-- 账号 -->
      <div class="layui-form-item">
        <label for="u_name" class="layui-form-label">
          <span class="x-red">*</span>
          <span>管理员账号</span>
        </label>
        <div class="layui-input-inline">
          <input type="text" maxlength="8" id="name" name="name" required lay-verify="name"
            autocomplete="off" class="layui-input">
        </div>
      </div>
      <!-- 管理员密码 -->
      <div class="layui-form-item">
        <label for="pass" class="layui-form-label">
          <span class="x-red">*</span>
          <span>管理员密码</span>
        </label>
        <div class="layui-input-inline">
          <input type="password" id="pass" aria-modal="21" name="pass" required lay-verify="pass"
            autocomplete="off" class="layui-input">
        </div>
      </div>

      <!-- 选择管理员状态 -->
      <div class="layui-form-item">
        <label for="username" class="layui-form-label">
            <span>选择状态</span>
        </label>
        <div class="layui-input-inline">
            <select id="is_open" name="is_open" class="valid" lay-filter="is_open">
							<option value="1">启用</option>
							<option value="0">停用</option>
            </select>
        </div>
      </div>

      <div class="layui-form-item">
        <label for="L_repass" class="layui-form-label"></label>
        <button  class="layui-btn" lay-filter="add" lay-submit="">增加</button>
      </div>
    </div>
	</div>
</body>
<script src="/public/layui/layui.js"></script>
<script src="/public/js/api.js"></script>
<script>
	layui.use(['form','layer'], function(){
    $ = layui.jquery;
    var form = layui.form;
    var  layer = layui.layer;
    //自定义验证规则
    form.verify({
      name: function(value){
        if(value.length < 2){
          return '账号至少得2个字符哦';
        }
      },
      pass: [/(.+){6,12}$/, '密码必须6到12位'],
    });
    //监听提交
    form.on('submit(add)', function(data){
      let d = data.field;
      _http.add_admin(d, (res) => {
        if(res.code == 0) {
          layer.alert(res.msg, {
            skin: 'layui-layer-molv'
            ,closeBtn: 0
          }, function(){
            parent.location.href='/admin/admin_list'
          });
        } else {
          layer.alert(res.msg, {icon: 6});
        }
      })
    })
  });
</script>
</html>
